﻿
Imports std
Imports centrosphere
Imports command = centrosphere.job.storage.command

Partial Public Class storageJobRandomDistributor
    Private Function find_key_distribute(ByVal inputJob As storageJob,
                                         ByVal targetJobs As vector(Of pair(Of UInt32, ijob))) As Boolean
        assert(Not inputJob Is Nothing)
        assert(Not targetJobs Is Nothing)
        assert(targetJobs.empty())
        For i As Int64 = 0 To key_mappings.size() - 1
            If key_mappings(i).contains_key(inputJob.key) Then
                targetJobs.push_back(make_pair(i, inputJob))
            End If
        Next
        Return Not targetJobs.empty()
    End Function

    Private Function find_key_fail_distribute(ByVal inputJob As storageJob,
                                              ByVal targetJobs As vector(Of pair(Of UInt32, ijob))) As Boolean
        Return find_key_distribute(inputJob, targetJobs) OrElse
               eva(storageJob(inputJob).result, False)
    End Function

    Private Function find_key_hash_distribute(ByVal inputJob As storageJob,
                                              ByVal targetJobs As vector(Of pair(Of UInt32, ijob))) As Boolean
        Return find_key_distribute(inputJob, targetJobs) OrElse
               hash_distribute(inputJob, targetJobs)
    End Function
End Class
